import numpy as np
import numpy.random as ran

A = ran.rand(10)  # 生成10个数，0.0-1.0之间的随机浮点数

B = np.fromfunction(lambda r,c:c,(4,5),dtype=np.int32)
print(B)

B1 = np.sum(B,axis=0)   # 行，对每一列求和
B2 = np.sum(B,axis=1)   # 列，对每一行求和

B_rows = np.sum(B,axis=1)
B3 = np.c_[B,B_rows]  # 将行的总和添加在最后一列

B_cols = np.sum(B3,axis=0)
B4 = np.r_[B3,[B_cols]]


def spreadsheet(A):
    '''能操作任何函数的二维数组 电子表格'''
    AC = np.sum(A,axis=1)
    A2 = np.c_[A,AC]
    AR = np.sum(A2,axis=0)
    return np.r_[A2,[AR]]





